<?php

namespace App\Transformers\System;

use Illuminate\Database\Eloquent\Model;
use League\Fractal\TransformerAbstract;

class RegionTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['parent'];

    protected $hidden = ['parent_id'];

    public function transform(Model $model)
    {
//        $model->makeHidden($this->hidden);
        return $model->attributesToArray();
    }

    public function includeParent(Model $model)
    {
        $parent = $model->parent;
        if (!$parent) {
            return $this->null();
        }
        return $this->item($parent, new self());
    }
}